package com.tenement.controller.foreground.user;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.tenement.base.constants.SysmConstants.state;
import com.tenement.base.exception.ParameterException;
import com.tenement.mybatis.entity.Collect;
import com.tenement.service.interfaces.ICollectService;

/**
 * 用户个人空间 我的收藏 我的约看 我的发布
 * 
 * @author wk
 *
 */
@Controller
public class UserZoneController {

	private static final Log logger = LogFactory.getLog(UserZoneController.class);

	@Autowired
	private ICollectService iCollecService;

	/**
	 * 进入用户个人空间，管理收藏，管理房源信息,
	 * 
	 * @return
	 */
	@RequestMapping(value = "/toReserveManageHtml.action")
	public String toReserveManageHtml() {
		logger.info("【-用户进入个人空间页面-】");
		return "view/personzone/reserve_manage";
	}

	/**
	 * 进入用户个人空间，管理收藏，管理房源信息,
	 * 
	 * @return
	 */
	@RequestMapping(value = "/toPublishManageHtml.action")
	public String toPublishManageHtml(HttpServletRequest request) {
		logger.info("【-用户进入个人空间页面-】");
		return "view/personzone/publish_manage";
	}
	
	
	/**
	 * 进入用户个人空间，管理收藏，管理房源信息,
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getCollectList.action")
	public @ResponseBody JSONObject getCollectList() {
		logger.info("【-获取用户租房列表-】");
		return iCollecService.getCollectList();
	}

	/**
	 * 模板引擎，页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(value = "/toUserCollectHtml.action")
	public String toUserCollectHtml() {
		return "view/personzone/collect_manage";
	}

	/**
	 * 删除用户收藏
	 * 
	 * @return
	 */
	@RequestMapping(value = "/deleteCollectUser.action")
	public @ResponseBody String deleteCollectUser(@RequestBody String c_id) {
		try {
			if (c_id == null || "".equals(c_id)) {
				throw new ParameterException("【删除收藏，参数c_id为空】");
			}
			boolean b = iCollecService.deleteCollectUser(new Collect(Integer.parseInt(c_id)));
			if (b) {
				logger.info("【删除成功c_id为" + c_id + "】");
				return state.Success;
			} else {
				logger.info("【删除失败c_id为" + c_id + "】");
				return state.Failed;
			}
		} catch (ParameterException p) {
			logger.error("【删除收藏功能，参数为空】");
			p.printStackTrace();
		}
		return state.Failed;
	}

}
